import socket
from DesModule import des_encrypt, des_decrypt

tcpserver = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
tcpserver.bind(("172.16.219.147", 2028))
tcpserver.listen(1)  # 只允许一个连接
KEY = "12345678"  # 保证KEY长度为8

conn, addr = tcpserver.accept()
print("Connection from:", addr)

data = conn.recv(1024)
decrypted_message = des_decrypt(data.decode("utf-8"), KEY)
print("Received:", decrypted_message)

ret_data = input("Please reply: ")
encrypted_reply = des_encrypt(ret_data, KEY)
conn.send(encrypted_reply.encode('utf-8'))

conn.close()
tcpserver.close()
